package params

import (
	"errors"
	"strings"
)

type ScopeListRequest struct {
	ListRequest
	Name string `form:"name"`
	Code string `form:"code"`
}

type ScopeUpdateRequest struct {
	PartnerId   uint64
	Id          uint64 `uri:"id"`
	Code        string `form:"code" json:"code"`
	Name        string `form:"name" json:"name"`
	Description string `form:"description" json:"description"`
}

func (req *ScopeUpdateRequest) Validate() error {
	req.Name = strings.Trim(req.Name, " \t\n")
	req.Code = strings.Trim(req.Code, " \t\n")
	req.Description = strings.Trim(req.Name, " \t\n")
	if len(req.Name) == 0 || len(req.Code) == 0 {
		return errors.New("name or code can't be empty")
	}
	if req.PartnerId == 0 {
		return errors.New("partner_id can not be empty")
	}
	return nil
}

type ScopeCreateRequest struct {
	PartnerId   uint64
	Code        string `form:"code" json:"code"`
	Name        string `form:"name" json:"name"`
	Description string `form:"description" json:"description"`
}

func (req *ScopeCreateRequest) Validate() error {
	req.Name = strings.Trim(req.Name, " \t\n")
	req.Code = strings.Trim(req.Code, " \t\n")
	req.Description = strings.Trim(req.Name, " \t\n")
	if len(req.Name) == 0 || len(req.Code) == 0 {
		return errors.New("name or code can't be empty")
	}
	if req.PartnerId == 0 {
		return errors.New("partner_id can not be empty")
	}
	return nil
}

type InitScopeDataReq struct {
	PartnerId   	 uint64
	ScopeCode        string `form:"scope_code" json:"scope_code"`
	ScopeName        string `form:"scope_name" json:"scope_name"`
	ScopeDescription string `form:"scope_description" json:"scope_description"`
	AdminName 	 	 string `form:"admin_name" json:"admin_name"`
	AdminCode 	 	 string `form:"admin_code" json:"admin_code"`
	Domain 			 string `form:"domain" json:"domain"`
}

func (req *InitScopeDataReq) Validate() error {
	req.ScopeName = strings.Trim(req.ScopeName, " \t\n")
	req.ScopeCode = strings.Trim(req.ScopeCode, " \t\n")
	req.ScopeDescription = strings.Trim(req.ScopeDescription, " \t\n")
	if len(req.ScopeName) == 0 || len(req.ScopeCode) == 0 {
		return errors.New("scope_name or scope_code can't be empty")
	}
	if req.PartnerId == 0 {
		return errors.New("partner_id can not be empty")
	}

	req.AdminName = strings.Trim(req.AdminName, " \t\n")
	req.AdminCode = strings.Trim(req.AdminCode, " \t\n")
	if len(req.AdminName) == 0 || len(req.AdminCode) == 0 {
		return errors.New("admin_name or admin_code can't be empty")
	}
	req.Domain = strings.Trim(req.Domain, " \t\n")
	if req.Domain == ``{
		return errors.New("domain can not be empty")
	}

	return nil
}